<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<%--<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="main" %>
<main:main>

    <style>
        .absolute {
            position: absolute;
            top: 5px;
            z-index: 99;
            text-align: center;
            padding: 0;
            margin: 0;
            width: 16px;
            height: 16px;
            border-radius: 8px;
            line-height: 16px;
        }
    </style>
    <script>
        $(function () {
//	// IE版本判断
//	if ($.browser.msie && parseInt($.browser.version) < 7) {
//		$("#downnewbrs").dialog({width:700, height:300, modal:true, title:"请点击下面的链接下载最新版IE浏览器！"})

//	}
            <%--var account = ${sessionScope.account};--%>
            <%--alert(account);--%>

            <%--if(account == ""){--%>
            <%--window.location.href ="${pageContext.request.contextPath}/lonin.jsp";--%>
            <%--}--%>
            var lis;
            $.getJSON("${pageContext.request.contextPath}/v1/actors/getMenuInfo?userName=${sessionScope.account.userName}&accountId=${sessionScope.account.accountId}", function (data) {

                // 一级主菜单
                $(data).each(function (index, row) {
                    //加载xs菜单
                    if (row.children) {
                        l1_data = row.children;
                        var xsitems = '<ul id="accordion" class="nav nav-sidebar">';
                        xsitems += makeXsMenu(l1_data, this.id);
                        xsitems += '</ul>';
                        $("#xs_drop").append(xsitems);
                    }
//                    $("#middleNav").append($("<li class='dropdown' id='" + this.id + "'><a class='dropdown-toggle' data-toggle='dropdown' href='#'>" + this.title + "<span class='badge pull-right absolute' style='background-color: #1c94c4'></span></a></li>").data("menu", this));
                    $("#middleNav").append($("<li class='dropdown' id='" + this.id + "'><a class='topbar' href='#'>" + this.title + "<span class='badge pull-right absolute' style='background-color: #1c94c4'></span></a></li>").data("menu", this));

                });

                // 二级子菜单
                $("#middleNav li").hover(function () {
                    var self = $(this);
                    if (!self.hasClass("selected"))
                        self.addClass("menu_over");
                }, function () {
                    $(this).removeClass("menu_over");
                }).click(function () {
                    var self = $(this);
                    self.siblings().removeClass("selected");
                    self.removeClass("menu_over").addClass("selected");
                    $(".menu_inner .accordion").hide();

                    var submenu_accordion = self.data("submenu_accordion");

                    $("#side-menu").empty();

                    submenu_accordion = $("<ul  class='nav ' ></ul>");
                    submenu_accordion.data("mainmenu", self);

                    // 建立子菜单
                    var menuLevel1Title = self.data("menu").title;
                    $($(this).data("menu").children).each(function (index) {
                        //$("#side-menu").append($("<li><a href='#'><i class='fa fa-dashboard fa-fw'></i>"+this.title+"</a></li>").data("menu", this));

                        $('<li><a href="#"><i class="fa fa-dashboard fa-fw"></i>' + this.title + '<span class="fa arrow"></span></a> \
							 <ul  class="nav nav-second-level">' + creatSubmenu(this.children, this.title) + '\
		            </ul></li>').appendTo(submenu_accordion);

                        function creatSubmenu(submenus, menuLevel2Title) {
                            var submenudivs = "";
                            $(submenus).each(function (index) {
                                var smifirststr = "";
                                if (index == 0) {
                                    smifirststr = "smifirst";
                                }
                                var menuLevel3Title = this.title;


                                //告警管理导航栏加入消息提示badge
                                if (menuLevel3Title == "告警管理") {
                                    submenudivs += '<li id="warningManage" title3="' + menuLevel3Title + '" title2="' + menuLevel2Title + '" title1="' + menuLevel1Title + '" class="li2 ' + smifirststr + '"  onclick="changedPage(\'' + this.path + '\')"   ' +
                                        'path="' + this.path + '" ><a href="#">' + '<span class="badge pull-right" id="elecmes" style="background-color:#4D8AB3;"></span>&nbsp;<span id="handlemes" class="badge pull-right" style="background-color:#4D8AB3;margin-right:5px;"></span>' + this.title + '</a></li>';

                                } else {
                                    submenudivs += '<li id="' + this.id + '" title3="' + menuLevel3Title + '" title2="' + menuLevel2Title + '" title1="' + menuLevel1Title + '" class="li2 ' + smifirststr + '"  onclick="changedPage(\'' + this.path + '\')"   path="' + this.path +
                                        '" ><a href="#"><span class="badge pull-right" style="background-color: #1c94c4"></span>' + this.title + '</a></li>';

                                }
                            });
                            return submenudivs;
                        }
                    });


                    $("#side-menu").html(submenu_accordion).init();
                    self.data("submenu_accordion", submenu_accordion);

                    // 子菜单效果
                    $(".menu2title").click(function () {
                        $(".li2").hide();
                        $(this).siblings().show();
                        $(".zyimg6").removeClass("zyimg6s");
                        $(this).find(".zyimg6").addClass("zyimg6s");
                    });

                    // 显示左侧子菜单
                    $(".left_menu").show();
                    $(".sys_main").removeClass("fullscreen");

                    // 显示具体模块功能div 隐藏门户div
                    $("#module_div").show();
                    $("#portal_div").hide();

                    $(".smifirst:eq(0)", submenu_accordion).click();


                }).first().click();

                changedPage('/linkboard/pages/blank.jsp?moduleid=1519810775000');


            });
            // 三级菜单添加转到模块功能
            $(".li2").on("click", function () {

                if ($(this).attr("target") == '_blank') {
                    open(ctxPath + "/" + $(this).attr("path"));
                    return;
                }

                $(".li2").removeClass("selected");
                $(this).closest(".accordion").data("mainmenu").data("currmenu", this);
                $(this).addClass("selected");

                $("#mainfuncifr").attr("src", ctxPath + $(this).attr("path") + "&autoheightifrmid=mainfuncifr");
                $("#smb_title1").text(this.title1);
                $("#smb_title2").text(this.title2);
                $("#smb_title3").text(this.title3);
                $(".smb_toright").show();
                // 显示具体模块功能div 隐藏门户div
                $("#module_div").show();
                $("#portal_div").hide();
                $(".sys_main").removeClass("fullscreen");
            });


            leftmenuwidth = $(".left_menu").width();

            reportPosTop = $("#reportPos").css("top");

//	// 读取页面右上角弹出信息模版
//	$("<div/>").load(ctxPath+'/popout_notice_tmpl.jsp').appendTo("body");
//
            /*
             $.subscribeRoutedMessages({
             dest:"notice",
             beforeAjax:function() {
             if (!isshowing)
             return true;
             },
             afterAjax:function(data) {
             var popdiv = $("#popout_notic_div");
             popdiv.setTemplateElement(data.tmplid).processTemplate(data.data);

             $("a", popdiv).each(function(){
             var self = $(this);
             var href = self.attr("href");
             self.attr("clickhref", href).attr("href","#");
             })
             popdiv.animate({marginTop:0}, 1000).delay(20000).animate({marginTop:-40}, 1000, function(){
             isshowing = false;
             });
             isshowing = true;
             }
             });*/

            // 更改链接动作
            $("#popout_notic_div a").on("click", function () {
                var thisObj = this;
                var topifram = $.dialogTopIframe({
                    url: $(thisObj).attr("clickhref"),
                    buttons: {
                        '关闭': function () {
                            top.$(topifram).dialog("destroy");
                        }
                    },
                    width: $(window).width() - 50,
                    height: $(window).height() - 50,
                    title: $(thisObj).attr("title"),
                    modal: true
                });
            });

            //初始化程序到此结束
            //下面新增王哲斌的初始化。
            doFullTX();

            setInterval(
                getMesCount, 300 * 1000
            );


        });

        function toggle(id) {
            var $icoLeft = $('#icl-' + id);
            var $icoRight = $('#icr-' + id);
            var $obj = $('#collapse-' + id);

            if ($obj.css('display') == 'block') {
                $icoLeft.removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
                $icoRight.removeClass('fa-angle-up').addClass('fa-angle-down');
            } else {
                $icoLeft.removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
                $icoRight.removeClass('fa-angle-down').addClass('fa-angle-up');
            }

            $obj.slideToggle("slow", "linear");
        }

        function makeXsMenu(data, parent) {
            if (data == undefined) {
                return;
            }
            var item = '';
            if (data.length > 0) {
                $.each(data, function (index, row) {
                    if (row.children) {
                        item += '<a href="javascript:;">';
                        item += '<li id="menu-' + row.id + '">';
                        item += '<div onclick="toggle(\'' + row.id + '\')">';
                        item += '<i id="icl-' + row.id + '" class="fa fa-plus-square-o"></i>';
                        item += '<span class="text">' + row.title + '</span>';
                        item += '<i id="icr-' + row.id + '" class="fa fa-angle-down pull-right"></i>';
                        item += '</div>';
                        item += '</a>';
                        item += '<ul style="display:none" id="collapse-' + row.id + '">';
                        var sub_data = row.children;
                        $.each(sub_data, function (subidx, subrow) {
                            var subitem = '<li id="menu-' + subrow.id + '" data-parent="menu-' + row.id + '">';
                            if (subrow.path) {
                                subitem += '<div style="padding: 10px"><a href="javascript:;" onclick="changedPage2(\'' + subrow.path + '\')"><span class="text">' + subrow.title + '</span></a><div>';
                            }
                            subitem += '</li>';
                            item += subitem;
                        });
                        item += '</ul>';
                    } else {
                        item += '<a href="javascript:;">';
                        item += '<li id="menu-' + row.id + '">';
                        item += '<i class="fa fa-laptop"></i><span class="text">' + row.title + '</span>';
                        item += '</a>';
                    }
                    item += '</li>';
                });
            }
            return item;
        }

        function getMesCount() {
            //账户管理   1319810779000
            var platformCode = "${sessionScope.account.platform_code}";
            var isSuper = "${sessionScope.account.isSuper}";
            if (platformCode == "qiqi" && isSuper == "1") {
                getReconCount();
            }
            timeTask();

        }

        function getWidthOfSpan() {
            var spans = $(".absolute");
            for (var i = 0; i < spans.length; i++) {
                var span = spans.eq(i);
                if (parseInt(span.html()) < 10) {
                    span.width(16);
                } else if (parseInt(span.html()) < 100) {
                    span.width(20);
                } else {
                    span.width(24);
                }
            }
        }

        function changedPage(obj) {
            if (obj == '/linkboard/dashboard/dash.jsp?moduleid=1319811000002') {//如果打开dashboard页，侧导航栏隐藏
                $("#all_side_menu,.sidebar,.sidebarv2").animate({
                    'left': '-250px'
                }, 200, function () {
                    $("#mainfuncifr").attr("src", obj + "&autoheightifrmid=mainfuncifr");
                });
                $("nav").css('position','relative').slideUp(1000);
                $("#mainfuncifr").css('height','100%');
                $('#showmenu').show();
            } else {
                $("#all_side_menu,.sidebar,.sidebarv2").animate({
                    'left': '0px'
                }, 300);
                $("#mainfuncifr").attr("src", obj + "&autoheightifrmid=mainfuncifr");
                $('#showmenu').hide();
                $("nav").css('position','relative').slideDown(1000);
                $("#mainfuncifr").css('height','93.6%');
            }
            getMesCount();
        }

        function changedPage2(obj) {
            $('#hamburger').click();
            if (obj == '/linkboard/dashboard/dash.jsp?moduleid=1319811000002') {//如果打开dashboard页，侧导航栏隐藏
                $("#all_side_menu,.sidebar,.sidebarv2").animate({
                    'left': '-250px'
                }, 200, function () {
                    $("#mainfuncifr").attr("src", obj + "&autoheightifrmid=mainfuncifr");
                });
                $("nav").css('position','relative').slideUp(1000);
                $("#mainfuncifr").css('height','100%');
                $('#showmenu').show();
            } else {
                $("#all_side_menu,.sidebar,.sidebarv2").animate({
                    'left': '0px'
                }, 300);
                $("#mainfuncifr").attr("src", obj + "&autoheightifrmid=mainfuncifr");
                $('#showmenu').hide();
                $("nav").css('position','relative').slideDown(1000);
                $("#mainfuncifr").css('height','93.6%');
            }
            getMesCount();
        }

        function changedPageindex(obj) {
            userName = '${sessionScope.account.userName}';
            if (userName == 'admin') {
                $("#mainfuncifr").attr("src", obj + "&autoheightifrmid=mainfuncifr");
            }
        }


        //填充头像
        //wzb
        function doFullTX() {

            var str;
            if ("" != "${sessionScope.account.platform_name}") {
                str = '<span  color="#0c0">${sessionScope.account.nickName}</span >  隶属于  <span   color="#c00">${sessionScope.account.platform_name}</span >';
            } else {
                str = '<span  color="#0c0">${sessionScope.account.nickName}</span > ';
            }

            $("#index_touxiang").html('<img style="width: 64px; height: 64px;border-radius:32px" src="${sessionScope.account.avatar}">');
            $("#index_name").html(str);

        }


        function getReconCount() {
            $.ajax({
                url: '${pageContext.request.contextPath}/v1//actors/company/reconcount',
                type: 'POST',
                datatype: 'json',
                contentType: 'application/json;charset=utf-8',
                Accept: 'application/json',
                cache: false,
                success: function (data, textStatus, jqXHR) {
                    var count = data.data;
                    if (parseInt(count) === 0) {
                        $("#1319810779012 .badge").html("");
                        $("#1319810779000 .badge").html("");
                    } else {
                        $("#1319810779012 .badge").html(count + '&nbsp;<i class="fa fa-envelope-o" aria-hidden="true"></i>');
                        $("#1319810779000 .badge").html(count);
                        getWidthOfSpan();
                    }
                }
            });
        }


        var elecCount = 0;
        var handleCount = 0;
        var allCount = 0;

        //电量告警消息
        function timeTask() {
            querySnsLowElec();
            queryHandleMesCount();
        }
        function querySnsLowElec() {
            var params = new Object();
            params.lowElectric = 40;//目前先限定低于40为低电量
            params.platformCode = "${sessionScope.account.platform_code}";

            $.ajax({
                url: '${pageContext.request.contextPath}/v1/rent/sns/sn/electric/infos/low',
                type: 'POST',
                datatype: 'json',
                contentType: 'application/json;charset=utf-8',
                Accept: 'application/json',
                data: JSON.stringify(params),
                cache: false,
                success: function (data, textStatus, jqXHR) {

                    if (data.data.length == 0) {
                        elecCount = 0;
                        $("#warningManage #elecmes").html("");
                    } else {
                        elecCount = data.data[0].count;
                        $("#warningManage #elecmes").html(elecCount + '&nbsp;<i class="fa fa-bolt" aria-hidden="true"></i>');
                    }
                    allCount = elecCount + handleCount;
                    if (allCount == 0) {
                        $("#1319810800001 span").html("");
                    } else {
                        $("#1319810800001 span").html(allCount);
                    }

                }
            });
        }

        //异常还车消息(count)
        function queryHandleMesCount() {
            var params = new Object();
            params.platformCode = "${sessionScope.account.platform_code}";
//            params.platformCode = "longshang"
            params.mesType = 1;
            params.readState = 1;//未读
            $.ajax({
                url: '${pageContext.request.contextPath}/v1/rent/sns/sn/handle/mescount',
                type: 'POST',
                datatype: 'json',
                contentType: 'application/json;charset=utf-8',
                Accept: 'application/json',
                data: JSON.stringify(params),
                cache: false,
                success: function (data, textStatus, jqXHR) {
                    handleCount = data.data;
                    if (handleCount == 0) {
                        $("#warningManage #handlemes").html("");
                    } else {
                        $("#warningManage #handlemes").html(handleCount + '&nbsp;<i class="fa fa-envelope-square" aria-hidden="true"></i>');
                    }
                    allCount = elecCount + handleCount;
                    if (allCount == 0) {
                        $("#1319810800001 span").html("");
                    } else {
                        $("#1319810800001 span").html(allCount);
                    }

                }
            });

        }

        function showmenu(){
            if($('nav').css('display')=='none'){
                $('nav').slideDown();
            }else{
                $('nav').slideUp();
            }
        }


    </script>

    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0;height:6.4%;position: absolute;z-index: 20">
        <div class="navbar-header">
                <%--<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">--%>
            <button id="hamburger" type="button" class="navbar-toggle" data-toggle="collapse" data-target="#xs_drop"
                    aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href='#'
               onclick="changedPageindex('/linkboard/pages/blank.jsp?moduleid=1519810775000')">Link</a>
        </div>
        <!-- /.navbar-header -->
        <ul class="nav navbar-top-links navbar-right hidden-xs">

            <!-- /.dropdown -->
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                    <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
                </a>
                <ul class="dropdown-menu dropdown-user">
                        <%--<li><a href="#"><i class="fa fa-user fa-fw"></i> User Profile</a>--%>
                        <%--</li>--%>
                        <%--<li><a href="#"><i class="fa fa-gear fa-fw"></i> Settings</a>--%>
                        <%--</li>--%>
                        <%--<li class="divider"></li>--%>
                    <li><a href="login.html"><i class="fa fa-sign-out fa-fw"></i> Logout</a>
                    </li>
                </ul>
                <!-- /.dropdown-user -->
            </li>
            <!-- /.dropdown -->
        </ul>
        <!-- /.navbar-top-links -->

            <%--中间--%>
        <ul class="nav navbar-top-links hidden-xs" id="middleNav">

        </ul>

        <!-- /.dropdown -->
        <div class="visible-xs">
            <div id="xs_drop" class="collapse navbar-collapse colla" style="height: 100%;float: left;position: absolute;background-color: #f8f8f8">

            </div>
        </div>


        <!--这里增加头像 和集团名称-->


        <div id="all_side_menu" class="hidden-xs">
            <div class="navbar-default sidebarv2" role="navigation" style="margin-top: 25px">
                    <%-- aa:${sessionScope.nickname}:
                             ${sessionScope.user.userName}--%>

                <div class="col-lg-12" id="index_touxiang" style="text-align:center;">
                    <img style="width: 64px; height: 64px;border-radius: 32px"
                         src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2739621087,1409538041&fm=200&gp=0.jpg">
                </div><!--头像-->
                <div class="col-lg-12" id="index_name" style="height:20px;text-align:center;margin-top: 10px;">王哲斌 隶属于
                    集团<img src=""></div><!--信息-->

            </div>
            <!--头像和集团名称结束-->
            <div style="margin-top: 140px;" class="navbar-default sidebar" role="navigation">
                <div class="sidebar-nav navbar-collapse" id="side-menu">

                </div>
                <!-- /.sidebar-collapse -->
            </div>
            <!-- /.navbar-static-side -->
        </div>
    </nav>
    <a id="showmenu" class="navbar-brand" href='#'
       onclick="showmenu()" style="position: absolute;width: 3%;line-height: 3%;top:60px;right:40px;display:none;z-index: 30;color:white">Menu</a>
    <iframe id="mainfuncifr" frameborder='0' style="width: 100%; height: 93.6%; border: 0"></iframe>
</main:main>